/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package authentification.dao;

import authentification.entitie.UserAuth;
import dao.DaoAbstract;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.NonUniqueResultException;
import javax.persistence.PersistenceContext;

/**
 *
 * @author loic.vaugeois
 */
@Stateless
public class DaoUserAuth extends DaoAbstract<UserAuth> implements DaoUserAuthLocal {
    @PersistenceContext(unitName = "EJBProjetEFPAuth")
    private EntityManager em;

    protected EntityManager getEntityManager() {
        return em;
    }

    public DaoUserAuth() {
        super(UserAuth.class);
    }

/*
 ************************METHODES
 */
    public UserAuth findLogin(String login){
        try{
        return (UserAuth)em.createNamedQuery("UserAuth.findUser").setParameter("loginUser", login).getSingleResult();
        }catch(NoResultException noResutlExcep){
            return null;
        }catch(NonUniqueResultException noUniqueExcep){
            throw new NonUniqueResultException("Erreur de base de donnée, le login devrait être UNIQUE. Erreur: "+noUniqueExcep.getMessage());
        }

    }
}
